/**
 * Created by LIAV2 on 8/24/2016.
 */
angular.module("detail",['ngRoute','ngAnimate','ngFileUpload'])
    .service('merchantService', function ($http, $rootScope) {
        var service = {
            merchantInfo: function (cb) {
                $rootScope.imgPath = 'http://zha-ita112-w7:8080/';
                $rootScope.permission = false;
                var req = {
                    method: "GET",
                    url: "/merchant/loadMerchant"
                };
                $http.get('/merchant/loadMerchant')
                    .then(function (res) {
                        if(!res.data.error){
                            $rootScope.permission = true;
                            $rootScope.merchantInfo = res.data;
                        }
                        // console.log("service:....."+ $rootScope.merchantInfo);
                        if(cb){
                            cb(res.data)
                        }
                    });

            }
        };
        return service;
    })
    // .run(function ($rootScope, $location, $timeout, $http,merchantService) {
    //     $rootScope.$on('$routeChangeStart', function () {
    //         var url = $location.url();
    //         $rootScope.permission = true;
    //         if (url == '/home' || url == '/food' || url == '/order') {
    //
    //             merchantService.merchantInfo(function(data) {
    //                 if (data) {
    //                     $rootScope.merchantInfo = data;
    //                     $rootScope.permission = true;
    //                 } else {
    //                     $rootScope.permission = false;
    //                 }
    //             })
    //         }
    //     })
    // })
